﻿using furion.blog.Domain.IRepositories;
using furion.blog.Domain.Mongo;
using furion.blog.Domain.Query.WxRequestLog;
using furion.blog.Domain.Shared;
using Furion.DependencyInjection;
using Furion.FriendlyException;
using MongoDB.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.EntityFramework.Core.Repositories
{
    public class WxRequestLogRepository : IWxRequestLogRepository,ISingleton
    {

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageVO> List(WxRequestLogListQuery query) {
            try
            {
                var (ret, totalCount, pageCount) = await DB.PagedSearch<WxRequestLog>()
                    //.Match(query.Exp())
                    .Match(query.Filter())
                    .Sort(t => t.Ts, Order.Descending)
                    .PageSize(query.PageSize)
                    .PageNumber(query.PageIndex)
                    .ExecuteAsync();
                return new PageVO { Total = totalCount, Records = ret };
            }
            catch (Exception ex) {
                throw Oops.Oh(ex.Message);
            }
        }

    }
}
